package com.atguigu.yygh.common.config;

import com.google.common.base.Predicates;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * @author mgx
 * @version 1.0
 * @description: Swagger2配置类
 * @date 2022/8/20 23:42
 */
@SpringBootConfiguration
@EnableSwagger2 // 开启swagger支持
public class Swagger2Config {

    @Bean
    public Docket getAdminDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("Admin")
                .apiInfo(getAdminApiInfo())
                .select()
                //只显示admin路径下的页面
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build();
    }

    private ApiInfo getAdminApiInfo() {
        return new ApiInfoBuilder()
                .title("管理员系统使用")
                .description("尚医通挂号平台之管理员系统")
                .version("1.0")
                .contact(new Contact("mgx", "http://www.atguigu.com", "756841734@qq.com"))
                .build();
    }

    // 每一个docket对象对应一组
    @Bean
    public Docket getApiDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("Api")
                .apiInfo(getApiInfo())
                .select()
                //只显示admin路径下的页面
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build();
    }

    // ApiInfo是对当前组的说明信息
    private ApiInfo getApiInfo() {
        return new ApiInfoBuilder()
                .title("第三方对接系统")
                .description("尚医通挂号平台之第三方对接系统")
                .version("1.0")
                .contact(new Contact("mgx", "http://www.atguigu.com", "756841734@qq.com"))
                .build();
    }

    @Bean
    public Docket getUserDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("User")
                .apiInfo(getUserInfo())
                .select()
                //只显示admin路径下的页面
                .paths(Predicates.and(PathSelectors.regex("/user/.*")))
                .build();
    }

    private ApiInfo getUserInfo() {
        return new ApiInfoBuilder()
                .title("用户系统")
                .description("尚医通挂号平台之用户系统")
                .version("1.0")
                .contact(new Contact("mgx", "http://www.atguigu.com", "756841734@qq.com"))
                .build();
    }
}
